#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
const int maxn = 8877691;
long long a[maxn];
void init()
{
	for(long long i = 0;i<10;i++) a[i] = i;
	int cnt = 10;
	for(int i = 1;cnt<maxn;i++)
	{
		int flag[11]={0};
		long long tmp = a[i];
		while(tmp)
		{
			long long t = tmp%10;
			flag[t] = 1;
			tmp = tmp/10;
		}
		for(int j = 0;j<10;j++)
		{
			if(!flag[j])
			{
				a[cnt++] = a[i]*10+j; 
			}
		}
	}
}
int main()
{
	init();
	int n;
	while(scanf("%d",&n)!=EOF)
	{
		printf("%I64d\n",a[n-1]);
	}
}
